package com.xuecheng.teaching.controller;

import com.xuecheng.api.comment.model.CommentModel;
import com.xuecheng.api.comment.model.CommentStaticsModel;
import com.xuecheng.api.comment.model.QuerryCommentModel;
import com.xuecheng.api.comment.model.ReplyModel;
import com.xuecheng.api.comment.model.dto.CommentDTO;
import com.xuecheng.api.comment.model.dto.ReplyDTO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.uaa.LoginUser;
import com.xuecheng.teaching.agent.CommentApiAgent;
import com.xuecheng.teaching.common.util.UAASecurityUtil;
import com.xuecheng.teaching.service.TeachingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Slf4j
@RestController
public class TeachingController {
    @Autowired
    private TeachingService teachingService;

    @Autowired
    private CommentApiAgent commentApiAgent;

    /**
     * 课程 添加 评论
     * @param model
     * @return
     */
    @PostMapping("/course-comment")
    public CommentDTO creatComment(@RequestBody CommentModel model) {
        LoginUser user = UAASecurityUtil.getUser();
        model.setLoginUser(user);

        CommentDTO commentDTO = teachingService.createComment(model);

        return commentDTO;
    }


    //查询课程评论列表
    @PostMapping("course-comment/for-course")
    public PageVO querryCommentList(PageRequestParams params, @RequestBody QuerryCommentModel model) {
        LoginUser user = UAASecurityUtil.getUser();

        PageVO pageVO = teachingService.querryCommentList(params,model);

        return pageVO;
    }

    //课程评论数据统计
    @GetMapping("course-comment/course-statistics/{targetId}")
    public CommentStaticsModel commentStatistics(@PathVariable(value = "targetId")Long targetId) {

        LoginUser user = UAASecurityUtil.getUser();

        CommentStaticsModel commentStaticsModel = teachingService.commentStatistics(targetId);

        return commentStaticsModel;
    }

    //为评论点赞
    @PostMapping("course-comment/praise/{commentId}")
    public Boolean likeComment(@PathVariable(value = "commentId")Long commentId) {

        LoginUser user = UAASecurityUtil.getUser();

        Boolean result = teachingService.praiseComment(commentId,user.getUsername());

        return result;
    }

    //机构的评论列表1
    @PostMapping("course-comment/list")
    public PageVO<List<CommentDTO>> querryOrgCommentList( PageRequestParams params, @RequestBody QuerryCommentModel Model){

        Long companyId = UAASecurityUtil.getCompanyId();
        PageVO<List<CommentDTO>> pageVO = teachingService.querryOrgCommentList(params,Model,companyId);

        return pageVO;
    }

    //课程评论回复
    @PostMapping("course-comment-reply")
    public ReplyDTO commentReply( @RequestBody ReplyModel Model){

        ReplyDTO replyDTO = teachingService.commentReply(Model);

        return replyDTO;
    }

    //删除ById
    @DeleteMapping("m/course-comment/{commentId}")
    public Boolean deleteCommentById( @PathVariable Long commentId){

        Boolean flag = teachingService.deleteCommentById(commentId);

        return flag;
    }

    //批量删除
    @DeleteMapping("m/course-comment/batch-del/{commentIds}")
    public Boolean deleteComments(@PathVariable String[] commentIds){


        System.out.println(commentIds);

        Boolean flag = teachingService.deleteComments(commentIds);

        return flag;
    }

    //机构 所有 评论列表
    @GetMapping ("m/course-comment/list-all")
    public PageVO<List<CommentDTO>> querryOrgAllCommentList(PageRequestParams params){

        PageVO<List<CommentDTO>> pageVO = teachingService.querryOrgAllCommentList(params);

        return pageVO;
    }

}
